package com.jtpay.sdk.util;

import android.app.Activity;
import android.app.Dialog;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.jtpay.sdk.R;


/**
 * Created by lj on 2017/4/10 0010.
 */

public class PopupWindowUtil {
    private static Dialog mDialog;
    private static Activity mContext;

    public static void showLookCodeDialog(Activity context, int style, int layout, String content1, String content2, String coding, String about, int tag) {
        if (null == mDialog) {
            mDialog = new Dialog(context, style);
        }
        mContext = context;
        View popupView = mContext.getLayoutInflater().inflate(layout, null);
        TextView textView_content1 = (TextView) popupView.findViewById(R.id.tv_look_code);
        TextView textView_notice1 = (TextView) popupView.findViewById(R.id.tv_look_notice1);
        TextView textView_notice2 = (TextView) popupView.findViewById(R.id.tv_look_notice2);
        TextView textView_content = (TextView) popupView.findViewById(R.id.tv_about);
        TextView textView_cancel = (TextView) popupView.findViewById(R.id.cancel_pop_look_code);
        textView_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mDialog.dismiss();
            }
        });
        mDialog.setContentView(popupView);
        mDialog.show();
        Window window = mDialog.getWindow();
        window.setGravity(Gravity.CENTER); //可设置dialog的位置 set dialog position
        window.getDecorView().setPadding(0, 0, 0, 0); //消除边距 Eliminate the margin
        WindowManager m = context.getWindowManager();
        Display d = m.getDefaultDisplay();
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = (int) (d.getWidth() * 0.75);  //设置宽度充满屏幕  Set the width of the screen
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(lp);
        switch (tag) {
            case 1:
                textView_content.setVisibility(View.GONE);
                textView_notice1.setText(content1);
                textView_notice2.setText(content2);
                textView_content1.setText(coding);
                break;
            case 2:
                textView_content1.setVisibility(View.GONE);
                textView_notice1.setVisibility(View.GONE);
                textView_notice2.setVisibility(View.GONE);
                String versions = context.getResources().getString(R.string.channel_text, about);
                textView_content.setText(versions);
                break;
            default:
                break;
        }

    }
}
